<html>
<head>
<#import "/common/common.ftl" as netCommon>
<@netCommon.commonStyle />
<title></title>
<@netCommon.commonScript />
<@netCommon.commonLayui /> 
</head>
<body class="layui-layout-body show-scroll-y">
	<div class="layuimini-container">
		<div class="layuimini-main">
			<fieldset class="layui-elem-field layui-field-title" id="searchField">
				<legend>字典管理</legend>
			</fieldset>
			<form class="layui-form" lay-filter="queryForm" id="queryForm">
				<div class="layui-row layui-col-space15">
					<div class="layui-col-md4">
						<div class="layui-form-item">
							<label class="layui-form-label">字典类型</label>
							<div class="layui-input-block layui-form" lay-filter="lxjpFilter">
								<select name="lxjp" id="lxjp" lay-filter="lxjp" lay-search="">
								</select>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-xs12 btn-right">
						<button type="button" class="layui-btn" id="reloadZd"
								lay-filter="data-add-btn">
								<i class="layui-icon">&#xe669;</i> 更新缓存
						</button>
						<button type="button" class="layui-btn" id="toAdd"
								lay-filter="data-add-btn">
								<i class="layui-icon">&#xe624;</i> 新 增
						</button>
					</div>
				</div>
				<div class="layui-row layui-col-space15">
					<div class="layui-col-md12">
						<div class="layui-card">
							<table id="listData" lay-filter="listData"></table>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		layui.use([ 'table', 'form', 'jquery' ], function() {
			let table = layui.table;
			let form = layui.form;
			form.on('select(lxjp)', function(data){
				reloadList();
			});
			zdCommon.initZdLxjpList("#lxjp", "",true, function() {
				form.render('select', 'lxjpFilter');
			});
			//表格数据加载
			var tableList = table.render({
				"elem":"#listData",
				"url":basePath+"/zd/zdList",
				"page":false,
				"method":"post",
				"where":fromSerialize("#queryForm"),
				"request":{"pageName":"currentPageNo","limitName":"pageSize"},
				"cols":[[
					{"title":"序号","width":80,"fixed":"left","type":"numbers"},
					{"field":"zddm","title":"字典代码"},
					{"field":"zdmc","title":"字典名称"},
					{"field":"lxjp","title":"字典类别"},
					{"field":"lxmc","title":"字典类别名称"},
					{"title":"操作","fixed":"right","width":130,"templet":function(d){
						var tem = [];
						tem.push('<div class="layui-btn-group">');
						tem.push('<button type="button" class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe63c;</i>编辑</button>');
						tem.push('<button type="button" class="layui-btn layui-btn-xs" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</button>');
						tem.push('</div">');
						return tem.join('');
					}}
				]]
			});
			function reloadList(){
				var params = fromSerialize("#queryForm");
				tableList.reload({
					"where":params,
					"page":{
						"currentPageNo":1
					}
				});
			}
			//操作栏
			table.on('tool(listData)', function(obj){
				var rData = obj.data;
				if(obj.event === 'delete'){
					delRydaxx(rData.objectid);
				}else if(obj.event === 'edit'){
					showEdit(rData.objectid);
				}
			});
			$("#toAdd").click(function() {
				var lxjpVal = form.val("lxjpFilter");
				var lxjpText = $("#lxjp").find("option:selected").text();
				if(lxjpVal.lxjp){
					showEdit("",lxjpVal.lxjp,lxjpText);	
				}else{
					showMsg.hold("请选择字典类型！");
				}
			});
			$("#reloadZd").click(function(){
				layer.load();
				$.ajax({
					url: basePath+"/zd/reloadCache",
					type: "post",
					dataType: "json",
					async: true,
					success: function(res){
						showMsg.hold(res.msg);
						layer.closeAll('loading');
					},
					error:function(){
						layer.closeAll('loading');
					}
				});
			});
			function showEdit(objid,lxjp,lxjpmc) {
				objid = objid == undefined ? "" : objid;
				layer.open({
					type : 2,
					title : '字典-编辑',
					closeBtn : 1,
					anim : 2,
					offset : '100px',
					area : ['500px', '270px' ],
					shadeClose : true,
					content : basePath + "/zd/edit?objectid=" + objid+"&lxjp="+lxjp+"&lxjpmc="+lxjpmc
				});
			}
			function delRydaxx(objid){
				showMsg.confirm("确定要删除吗？",function(){
					$.ajax({
						url: basePath+"/zd/delZd?objectid="+objid,
						type: "post",
						dataType: "json",
						success: function(data){
							showMsg.hold(data.msg);
							reloadList();
						}
					});
				});
			}
		});
	</script>
</body>
</html>